package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	timestamppb "google.golang.org/protobuf/types/known/timestamppb"
	"learn_grpc/4_protobuf_syntax/protobuf_syntax/proto"
	"time"
)

func main() {
	// 建立连接 grpc.WithTransportCredentials(insecure.NewCredentials())跳过证书验证
	conn, err := grpc.Dial("127.0.0.1:8080", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		panic(err)
	}
	defer conn.Close() //需要关闭连接，
	// 初始化客户端
	client1 := proto.NewGreeterClient(conn)
	resq := proto.HelloRequest{
		Name:    "John",
		AddTime: timestamppb.New(time.Now()),
	}
	//resq2 := proto.HelloRequest2{
	//	Name: "John",
	//	G:    proto.Gender2_FEMALE, //获取定义的枚举值
	//}
	//resq3 := proto.HelloRequest3{
	//	Name: "John",
	//	G:    proto.Gender2_FEMALE,
	//	Mp: map[string]string{
	//		name: "jiang",
	//	},
	//}
	//发出请求
	respon, err := client1.SayHello(context.Background(), &resq)
	if err != nil {
		panic(err)
	}
	fmt.Println(respon.Message)
}
